home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Toolbox / Visual Basic Toolbox (P.I.E.)(1996).ISO / error_hn / rdblib / rdblib.bas < prev    next >
Encoding:
BASIC Source File  |  1995-04-20  |  26.0 KB  |  674 lines

  1. ' Common Subroutine & Functions Module
  2. ' Provided by:
  3. '    Royce D. Bacon
  4. '    RDB Systems
  5. '    8942 W. Lawrence Ave.
  6. '    Milwaukee, WI  53225
  7. '    Compuserve ID: 70042,1001
  8. '
  9. ' You may use these routines in your own programs and
  10. ' distribute them or the compiled versions of them
  11. ' with your programs.  However, you may not distribute
  12. ' these routines alone for profit.
  13. '
  14. ' Payment for these routines is not required, but will
  15. ' always be appreciated.
  16. '
  17. Option Explicit
  18.  
  19. Global RB_systemname As String
  20. Global RB_version As String
  21. Global RB_Erraction As Integer
  22. Global Const RB_GRAY = &HC0C0C0
  23. ' Constants, etc. for screen capture/print function
  24. Global Const SW_HIDE = 0
  25. Global Const SW_SHOW = 5
  26. Declare Function ShowWindow Lib "User" (ByVal hwnd As Integer, ByVal nCmdShow As Integer) As Integer
  27.  
  28. ' Declares for log file routines
  29. Global RB_LogFileOpen As Integer   ' Indication if log file is open
  30. Global RB_DBLog As database
  31. Global RB_TblErrorLog As table
  32. Global RB_TblPerformanceLog As table
  33. Global RB_LogPerformanceData As Integer     ' Indicates if should log performance data
  34. Global RB_UserName As String            ' User name from ini file
  35. Global Const RB_STARTTASK = 1           ' Log start of task
  36. Global Const RB_ENDTASK = 2             ' Log end of task
  37.  
  38.  
  39.  
  40. ' Windows function declarations
  41.  
  42. Declare Function GetModuleUsage Lib "KERNEL" (ByVal InstanceID%) As Integer
  43.  
  44. '******************************************************
  45. '           DLL Declarations                          *
  46. '******************************************************
  47. Type POINTAPI
  48.     X As Integer
  49.     Y As Integer
  50. End Type
  51.  
  52. Declare Function LoadMenu Lib "User" (ByVal hInstance As Integer, ByVal lpString As String) As Integer
  53. Declare Function GetMenu Lib "User" (ByVal hwnd As Integer) As Integer
  54. Declare Function SetMenu Lib "User" (ByVal hwnd As Integer, ByVal hMenu As Integer) As Integer
  55. Declare Function HiliteMenuItem Lib "User" (ByVal hwnd As Integer, ByVal hMenu As Integer, ByVal wIDHiliteItem As Integer, ByVal wHilite As Integer) As Integer
  56. Declare Function GetMenuString Lib "User" (ByVal hMenu As Integer, ByVal wIDItem As Integer, ByVal lpString As String, ByVal nMaxCount As Integer, ByVal wFlag As Integer) As Integer
  57. Declare Function GetMenuState Lib "User" (ByVal hMenu As Integer, ByVal wId As Integer, ByVal wFlags As Integer) As Integer
  58. Declare Sub DrawMenuBar Lib "User" (ByVal hwnd As Integer)
  59. Declare Function GetSystemMenu Lib "User" (ByVal hwnd As Integer, ByVal bRevert As Integer) As Integer
  60. Declare Function GetSubMenu Lib "User" (ByVal hMenu As Integer, ByVal nPos As Integer) As Integer
  61. Declare Function GetMenuItemID Lib "User" (ByVal hMenu As Integer, ByVal nPos As Integer) As Integer
  62. Declare Function GetMenuItemCount Lib "User" (ByVal hMenu As Integer) As Integer
  63. Declare Function TrackPopupMenu Lib "User" (ByVal hMenu As Integer, ByVal wFlags As Integer, ByVal X As Integer, ByVal Y As Integer, ByVal nReserved As Integer, ByVal hwnd As Integer, lpReserved As Any) As Integer
  64. Declare Function InsertMenu Lib "User" (ByVal hMenu As Integer, ByVal nPosition As Integer, ByVal wFlags As Integer, ByVal wIDNewItem As Integer, ByVal lpNewItem As Any) As Integer
  65. Declare Function AppendMenu Lib "User" (ByVal hMenu As Integer, ByVal wFlags As Integer, ByVal wIDNewItem As Integer, ByVal lpNewItem As Any) As Integer
  66. Declare Function ModifyMenu Lib "User" (ByVal hMenu As Integer, ByVal nPosition As Integer, ByVal wFlags As Integer, ByVal wIDNewItem As Integer, ByVal lpString As Any) As Integer
  67. Declare Function RemoveMenu Lib "User" (ByVal hMenu As Integer, ByVal nPosition As Integer, ByVal wFlags As Integer) As Integer
  68. Declare Function DeleteMenu Lib "User" (ByVal hMenu As Integer, ByVal nPosition As Integer, ByVal wFlags As Integer) As Integer
  69.  
  70. Declare Function ExitWindows Lib "User" (ByVal dwReserved As Long, wReturnCode) As Integer
  71. Declare Function GetDeviceCaps Lib "GDI" (ByVal hDC As Integer, ByVal nIndex As Integer) As Integer
  72. Declare Function GetActiveWindow Lib "User" () As Integer
  73. Declare Sub GetCursorPos Lib "User" (lpPoint As POINTAPI)
  74. Declare Function GetSystemMetrics Lib "User" (ByVal nIndex As Integer) As Integer
  75. Declare Function GetFocus Lib "User" () As Integer
  76. Declare Function SetActiveWindow Lib "User" (ByVal hwnd As Integer) As Integer
  77. Declare Function GetModuleHandle Lib "Kernel" (ByVal lpModuleName As String) As Integer
  78. Declare Function GetModuleFileName Lib "Kernel" (ByVal hModule As Integer, ByVal lpFileName As String, ByVal nSize As Integer) As Integer
  79. Declare Function GetFreeSpace Lib "Kernel" (ByVal wFlags As Integer) As Long
  80.  
  81. 'Indices for GetSystemMetrics
  82. Global Const SM_CXSIZE = 30
  83. Global Const SM_CYSIZE = 31
  84.  
  85. 'Indices for GetDeviceCaps
  86. Global Const HORZRES = 8    '  Horizontal width in pixels
  87. Global Const VERTRES = 10   '  Vertical width in pixels
  88.  
  89. 'Menu flags for Add/Check/EnableMenuItem()
  90. Global Const MF_INSERT = &H0
  91. Global Const MF_CHANGE = &H80
  92. Global Const MF_APPEND = &H100
  93. Global Const MF_DELETE = &H200
  94. Global Const MF_REMOVE = &H1000
  95.  
  96. Global Const MF_BYCOMMAND = &H0
  97. Global Const MF_BYPOSITION = &H400
  98.  
  99. Global Const MF_SEPARATOR = &H800
  100.  
  101. Global Const MF_ENABLED = &H0
  102. Global Const MF_GRAYED = &H1
  103. Global Const MF_DISABLED = &H2
  104.  
  105. Global Const MF_UNCHECKED = &H0
  106. Global Const MF_CHECKED = &H8
  107. Global Const MF_USECHECKBITMAPS = &H200
  108.  
  109. Global Const MF_STRING = &H0
  110. Global Const MF_BITMAP = &H4
  111. Global Const MF_OWNERDRAW = &H100
  112.  
  113. Global Const MF_POPUP = &H10
  114. Global Const MF_MENUBARBREAK = &H20
  115. Global Const MF_MENUBREAK = &H40
  116.  
  117. Global Const MF_UNHILITE = &H0
  118. Global Const MF_HILITE = &H80
  119.  
  120. Global Const MF_SYSMENU = &H2000
  121. Global Const MF_HELP = &H4000
  122. Global Const MF_MOUSESELECT = &H8000
  123.  
  124. '  Menu item resource format
  125. Type MENUITEMTEMPLATEHEADER
  126.     versionNumber As Integer
  127.     offset As Integer
  128. End Type
  129.  
  130. Type MENUITEMTEMPLATE
  131.     mtOption As Integer
  132.     mtID As Integer
  133.     mtString As Long
  134. End Type
  135.  
  136. Global Const MF_END = &H80
  137.  
  138. '  System Menu Command Values
  139. Global Const SC_SIZE = &HF000
  140. Global Const SC_MOVE = &HF010
  141. Global Const SC_MINIMIZE = &HF020
  142. Global Const SC_MAXIMIZE = &HF030
  143. Global Const SC_NEXTWINDOW = &HF040
  144. Global Const SC_PREVWINDOW = &HF050
  145. Global Const SC_CLOSE = &HF060
  146. Global Const SC_VSCROLL = &HF070
  147. Global Const SC_HSCROLL = &HF080
  148. Global Const SC_MOUSEMENU = &HF090
  149. Global Const SC_KEYMENU = &HF100
  150. Global Const SC_ARRANGE = &HF110
  151. Global Const SC_RESTORE = &HF120
  152. Global Const SC_TASKLIST = &HF130
  153.  
  154. '******************************************************
  155. '*          OpenFile Modes                            *
  156. '******************************************************
  157. Global Const REPLACEFILE = 0
  158. Global Const READFILE = 1
  159. Global Const APPENDFILE = 2
  160. Global Const RANDOMFILE = 3
  161. Global Const BINARYFILE = 4
  162.  
  163.  
  164. '**************************************************
  165. ' Declares for screen grabber function
  166. '**************************************************
  167. Type lrect
  168.     Left As Integer
  169.     Top As Integer
  170.  
  171.     right As Integer
  172.     bottom As Integer
  173. End Type
  174. Declare Function GetDesktopWindow Lib "user" () As Integer
  175. Declare Function GetDC Lib "user" (ByVal hwnd%) As Integer
  176.  
  177. ' Note: The following Declare should be on one line:
  178. Declare Function BitBlt Lib "GDI" (ByVal hDestDC%, ByVal X%, ByVal Y%, ByVal nWidth%, ByVal nHeight%, ByVal hSrcDC%, ByVal XSrc%, ByVal YSrc%, ByVal dwRop&) As Integer
  179. Declare Function ReleaseDC Lib "User" (ByVal hwnd As Integer, ByVal hDC As Integer) As Integer
  180.  
  181. Declare Sub GetWindowRect Lib "User" (ByVal hwnd%, lpRect As lrect)
  182. Global TwipsPerPixel As Single
  183.  
  184.  
  185. 'Other API Declarations For Sound
  186. Declare Sub MessageBeep Lib "User" (ByVal wType As Integer)
  187. Declare Sub SndPlaySound Lib "MMSystem.dll" (ByVal WavFile$, ByVal wFlags As Integer)
  188.  
  189. Declare Function GetPrivateProfileInt Lib "Kernel" (ByVal lpAppName As String, ByVal lpKeyName As String, ByVal nDefault As Integer, ByVal lpFileName As String) As Integer
  190. Declare Function GetPrivateProfileString Lib "Kernel" (ByVal lpAppName As String, ByVal lpKeyName As String, ByVal lpDefault As String, ByVal lpReturnedString As String, ByVal nSize As Integer, ByVal lpFileName As String) As Integer
  191. Declare Function WritePrivateProfileString Lib "Kernel" (ByVal lpAppName As String, ByVal lpKeyName As String, ByVal lpString As String, ByVal lplFileName As String) As Integer
  192.  
  193. Function RB_Format_Phone_Num (psPhone_Num)
  194. ' This routine will format a phone number
  195. ' The routine always returns a right justified 12 character value
  196. ' Valid input formats and resulting outputs are (_ = blank):
  197. '   nnnnnnn - formatted as ____nnn-nnnn
  198. '   nnnnnnnnnn - formatted as nnn-nnn-nnnn
  199. '   All other inputs will be returned as entered, but right justified
  200.     Dim sWkPhone_Num As String
  201.  
  202.     sWkPhone_Num = Trim$(psPhone_Num)
  203.     Select Case True
  204.         Case Len(sWkPhone_Num) = 7      ' number w/o area code (nnnnnnn) format
  205.             RB_Format_Phone_Num = "    " & Left$(sWkPhone_Num, 3) & "-" & Right$(sWkPhone_Num, 4)
  206.         Case Len(sWkPhone_Num) = 10     ' number w/area code (nnnnnnnnnn) format
  207.             RB_Format_Phone_Num = Left$(sWkPhone_Num, 3) & "-" & Mid$(sWkPhone_Num, 4, 3) & "-" & Right$(sWkPhone_Num, 4)
  208.         Case Else
  209.             RB_Format_Phone_Num = Right$(Space$(12) & sWkPhone_Num, 12)
  210.  
  211.     End Select
  212.  
  213. End Function
  214.  
  215. Function RB_Rjustify (pnumber, pformat As String, pcol) As Single
  216.     ' ========================= RB_Rjustify ====================
  217.     ' Will print a number passed as parameter 1
  218.     ' according to the format passed as parameter 2
  219.     ' right justified on the column passed as parameter 3
  220.     ' Returns the leftmost column position where printing started
  221.     '
  222.     ' Example:
  223.     ' leftcol = RB_Rjustify(200, "###,###.##", 40)
  224.     ' will print "    200.00" with the rightmost 0 at column 40
  225.     '
  226.     Dim rbpos As Single
  227.     Dim rbstr As String
  228.     Dim rblen As Single
  229.     rbstr = Format$(pnumber, pformat)
  230.     rblen = printer.TextWidth(rbstr)
  231.     rbpos = pcol - rblen
  232.     printer.CurrentX = rbpos
  233.     printer.Print rbstr;
  234.     RB_Rjustify = rbpos
  235.  
  236. End Function
  237.  
  238. Sub RB_SetLogOptions ()
  239.     RB_CloseLog
  240.     RBLogOptions.Show MODAL
  241.     RB_OpenLog
  242.  
  243. End Sub
  244.  
  245. Function RB_StatusMsg (pTag) As String
  246.     ' Return status line portion of tag property
  247.     If InStr(1, pTag, "|") = 0 Then     ' No | separator
  248.         RB_StatusMsg = pTag                ' Use full string
  249.     Else
  250.         RB_StatusMsg = Mid$(pTag, InStr(1, pTag, "|") + 1)
  251.     End If
  252.  
  253. End Function
  254.  
  255. Function RB_Text_Format (instring As String, pwidth As Long)
  256.     ' ==================== RB_Text_Format ===================
  257.     ' Will return a string variable passed as parameter 1
  258.     ' formatted to print with a line length of parameter 2
  259.     ' It will break each line at the end of a word
  260.     '
  261.     ' Example:
  262.     ' newstring = RB_Text_Format(oldstring, 65)
  263.     ' Printer.Print newstring
  264.     ' will print the contents of oldstring as 65 character lines
  265.     '
  266.     Dim startpos As Integer, nextrtn As Integer, nextspace As Integer
  267.     Dim svstartpos As Integer
  268.     Dim svstatpos As Integer, svwkstring As String, wkinstring As String
  269.     Dim wkstring As String, outstring As String, gotstring As Integer
  270.     outstring = ""
  271.     wkinstring = Trim$(instring)
  272.     nextrtn = 0
  273.     startpos = 1
  274.     Do While startpos < Len(wkinstring)
  275.         gotstring = False
  276.         nextrtn = InStr(startpos, wkinstring, Chr$(13))
  277.         If nextrtn > 0 Then
  278.             wkstring = Mid$(wkinstring, startpos, nextrtn - startpos + 1)
  279.             ' Check for string less than 400 characters because long
  280.             ' strings cause an overflow error and definitely won't fit
  281.             ' on a single line
  282.             If Len(wkstring) < 400 Then
  283.                 If printer.TextWidth(wkstring) < pwidth Then
  284.                     outstring = outstring + wkstring
  285.                     startpos = nextrtn + 2
  286.                     gotstring = True
  287.                 End If
  288.             End If
  289.         End If
  290.         If Not gotstring Then
  291.             wkstring = ""
  292.             Do
  293.                 svwkstring = wkstring
  294.                 svstartpos = startpos
  295.                 nextrtn = InStr(startpos, wkinstring, " ")
  296.                 If nextrtn = 0 Then
  297.                     wkstring = wkstring + Mid$(wkinstring, startpos)
  298.                     svwkstring = wkstring
  299.                     startpos = Len(wkinstring) + 1
  300.                     svstartpos = startpos
  301.                 Else
  302.                     wkstring = wkstring + Mid$(wkinstring, startpos, nextrtn - startpos + 1)
  303.                     startpos = nextrtn + 1
  304.                 End If
  305.             Loop While printer.TextWidth(wkstring) <= pwidth And startpos <= Len(wkinstring)
  306.             startpos = svstartpos
  307.             outstring = outstring + svwkstring + Chr$(13) + Chr$(10)
  308.         End If
  309.     Loop
  310.     RB_Text_Format = outstring
  311.  
  312.  
  313. End Function
  314.  
  315. Function RB_Validate_Date (cdate As Control) As Integer
  316.     ' ================= RB_Validate_Date =====================
  317.     ' validates date contained in control passed as parameter 1
  318.     ' will return True if input is valid date, the string "__/__/__" or null
  319.     ' will display a msgbox with an "Enter a valid data" msg and return False
  320.     '      if the input date is invalid
  321.     '
  322.     ' Example:
  323.     ' TxtDate_LostFocus
  324.     '   IF Not RB_Validate_Date(TxtDate) then
  325.     '       Date.setfocus
  326.     '   End If
  327.     '
  328.     Dim wk_date As String
  329.     wk_date = cdate.Text
  330.     If Len(wk_date) = 6 And InStr(1, wk_date, "/") = 0 Then
  331.         wk_date = Left$(wk_date, 2) & "/" & Mid$(wk_date, 3, 2) & "/" & Right$(wk_date, 2)
  332.         cdate.Text = wk_date
  333.     End If
  334.     If wk_date = "__/__/__" Or wk_date = "" Then
  335.         RB_Validate_Date = True
  336.         cdate.Text = ""
  337.     ElseIf Not IsDate(wk_date) Then
  338.         Beep
  339.         MsgBox "Enter a valid date", , "Date Entry Error"
  340.         RB_Validate_Date = False
  341.     Else
  342.         RB_Validate_Date = True
  343.     End If
  344.  
  345. End Function
  346.  
  347. Sub ReadIni (AppName$, KeyName$, nDefault, DefaultStr$, ReturnStr$, Numeric%, IniFileName$)
  348. 'Note: IniFile should be in Windows Directory
  349.  
  350. ' Example Calling Code to Read Numeric Variable ------------------------------------------------------------------------------
  351.     'IniFileName$ = "MyINI.INI"        'name of ini file
  352.     'AppName$ = "MyApp"             'Name of application or section heading
  353.     'KeyName$ = "MyNumber"          'Keyword or variable name
  354.     'nDefault = 0                   'Default numeric value (for numeric variables)
  355.     'Numeric%=TRUE                  'Tell it we are looking for numeric value
  356.     'ReadIni AppName$, KeyName$, nDefault, DefaultStr$, ReturnStr$, Numeric%, IniFileName$
  357.  
  358. ' Example Calling Code to Read String Variable ------------------------------------------------------------------------------
  359.     'IniFileName$ = "MyINI.INI"        'name of ini file
  360.     'AppName$ = "MyApp"             'Name of application or section heading
  361.     'KeyName$ = "MyString"          'Keyword or variable name
  362.     'DefaultStr$ = "DefaultString"  'Default string        (for String variables)
  363.     'Dim RetStr As String * 255     'Create an empty string to be filled
  364.     'nSize% = 255                   'uncertain - possibly length of fill string
  365.     'Numeric%=FALSE                 'Tell it we are looking for a string
  366.     'ReadIni AppName$, KeyName$, nDefault, DefaultStr$, ReturnStr$, Numeric%, IniFileName$
  367.  
  368.  
  369. ' Read data from Private Profile (.ini) File
  370.     Dim nSize%, lenRetString%
  371.  
  372.     If Numeric% Then    'we are looking for integer input
  373.         Numeric% = GetPrivateProfileInt(AppName$, KeyName$, nDefault, IniFileName$)
  374.     Else
  375.         Dim RetStr As String * 255 'Create an empty string to be filled
  376.         nSize% = 255               'uncertain - possibly length of fill string
  377.         lenRetString% = GetPrivateProfileString(AppName$, KeyName$, DefaultStr$, RetStr$, nSize%, IniFileName$)
  378.         ReturnStr$ = Left$(RetStr$, lenRetString%)
  379.         
  380.     End If
  381.  
  382.  
  383. End Sub
  384.  
  385. Sub SaveIni (AppName$, IniFileName$, KeyName$, NewVal$)
  386.     
  387.     ' Update INI file
  388.  
  389. 'Note: IniFile should be in Windows Directory
  390.  
  391. 'Example calling Code to create or update ini -------------------------------------------------------------------------------------
  392.     'IniFileName$ = "MyINI.INI"        'name of ini file
  393.     'AppName$ = "MyApp"             'Name of application or section heading
  394.     'KeyName$ = "MyNumber"          'Keyword or variable name
  395.     'NewVal$="MyNewValue"           'if Numeric value convert it to string
  396.     'SaveIni AppName$, IniFileName$, KeyName$, NewVal$
  397.  
  398.     Dim ResultCode%
  399.         
  400.     ResultCode% = WritePrivateProfileString(AppName$, KeyName$, NewVal$, IniFileName$)
  401.     If ResultCode% = 0 Then
  402.         Beep
  403.         MsgBox "Error updating INI file!", 16, "ERROR!"
  404.     End If
  405.  
  406. End Sub
  407.  
  408. Sub ShellAndWait (CommandString$)
  409.   ' ============== ShellAndWait =====================
  410.   ' Will start (via Shell Function) the command passed as parameter 1
  411.   ' and wait until the command has completed and the window closed
  412.   '
  413.   ' Example:
  414.   ' ShellAndWait("COPY A.TXT B.TXT")
  415.   ' B.TXT will be available now
  416.   '
  417.  
  418.   Dim ID%, X%
  419.  
  420.   ID% = Shell(CommandString$, 3)
  421.   Do
  422.     X% = DoEvents()
  423.   Loop Until GetModuleUsage(ID%) = 0
  424.  
  425. End Sub
  426.  
  427. Sub Form3D (formname As Form)
  428.    ' This code came from Visual Basic Tips And Techniques 94
  429.    ' Tip Submitted By: Matej Nastran
  430.    ' Modified to set 3-D based upon control type instead of tag = 3-D
  431.    Dim drkgray As Long, fullwhite As Long
  432.    Dim i As Integer, dw As Integer, Do3D As Integer
  433.    Dim ctop As Integer, cleft As Integer, cright As Integer, cbottom As Integer
  434.  
  435.     ' Outline a form's text and combobox controls for 3D look
  436.  
  437.     Dim cname As Control
  438.  
  439.     drkgray = RGB(128, 128, 128)
  440.     fullwhite = RGB(255, 255, 255)
  441.  
  442.     dw = formname.DrawWidth
  443.     formname.DrawWidth = 1      'this suits me best
  444.     For i = 0 To (formname.Controls.Count - 1)
  445.         Set cname = formname.Controls(i)
  446.         If TypeOf cname Is TextBox Then
  447.             Do3D = True
  448.         ElseIf TypeOf cname Is ComboBox Then
  449.             Do3D = True
  450.         Else
  451.             Do3D = False
  452.         End If
  453.         If Do3D Then
  454.             ctop = cname.Top - Screen.TwipsPerPixelY
  455.             cleft = cname.Left - Screen.TwipsPerPixelX
  456.             cright = cname.Left + cname.Width
  457.             cbottom = cname.Top + cname.Height
  458.             formname.Line (cleft, ctop)-(cright, ctop), drkgray
  459.             formname.Line (cleft, ctop)-(cleft, cbottom), drkgray
  460.             formname.Line (cleft, cbottom)-(cright, cbottom), fullwhite
  461.             formname.Line (cright, ctop)-(cright, cbottom), fullwhite
  462.         End If
  463.     Next i
  464.     formname.DrawWidth = dw
  465. End Sub
  466.  
  467. Sub RB_Center (str_to_print As String, line_no, skip_line As Integer)
  468.     ' ============= RB_Center ==============================
  469.     ' Will center a string passed as parameter 1
  470.     ' on printer line passed as parameter 2 or current line if parameter 2 = 0
  471.     ' Will skip to next line if parameter 3 = true
  472.     ' e.g. RB_Center "This String Will Be Centered On Line 3", 3, true
  473.     '
  474.     Dim col_to_print_at As Single
  475.     col_to_print_at = ((printer.ScaleWidth - printer.TextWidth(str_to_print)) / 2) + printer.ScaleLeft
  476.     printer.CurrentX = col_to_print_at
  477.     If line_no <> 0 Then
  478.         printer.CurrentY = line_no
  479.     End If
  480.     If skip_line Then
  481.         printer.Print str_to_print
  482.     Else
  483.         printer.Print str_to_print;
  484.     End If
  485.  
  486. End Sub
  487.  
  488. Sub RB_CloseLog ()
  489.     On Error Resume Next
  490.     RB_TblPerformanceLog.Close
  491.     RB_TblErrorLog.Close
  492.     RB_DBLog.Close
  493.  
  494. End Sub
  495.  
  496. Function RB_ErrorHandler (pform As String, proutine As String) As Integer
  497.     ' =================== RB_ErrorHandler =========================
  498.     ' Displays dialog indicating error and allows user to
  499.     ' print problem report form, obtain help on error condition,
  500.     ' abort program, retry the function, or ignore the error
  501.     '
  502.     ' Example of using RB_ErrorHandler
  503.     ' erraction = RB_ErrorHandler("FormName", "Routine")
  504.     ' Select Case erraction
  505.     ' Case 1
  506.     '     Resume 0      ' Retry option selected
  507.     ' Case 2
  508.     '     Resume Next   ' Ignore option selected
  509.     ' End Select
  510.     '
  511.     ' To use in your projects include RDBLIB.BAS, RBERRFRM.FRM,
  512.     ' RBPROBRP.FRM, RBSCRN.FRM
  513.     
  514.     Dim RB_err As Integer
  515.     Dim RB_error As String
  516.     Dim RB_errl As Long
  517.     Dim RB_Msg As String
  518.     RB_err = Err
  519.     RB_error = Error$
  520.     RB_errl = Erl
  521.     SndPlaySound "crash.wav", 2
  522.     Beep
  523.     RB_Msg = "A " & RB_error & " error (" & RB_err & ") has occurred"
  524.     If RB_errl <> 0 Then
  525.         RB_Msg = RB_Msg & " at line " & RB_errl
  526.     End If
  527.     RB_Msg = RB_Msg + " in routine " & proutine & " of form " & pform
  528.     RB_Msg = RB_Msg & "."
  529.     If RB_err = 3051 Then
  530.         RB_Msg = RB_Msg & "  This error is usually caused because another user on the network, "
  531.         RB_Msg = RB_Msg & "another function on this workstation, is performing a function that "
  532.         RB_Msg = RB_Msg & "requires exclusive use of the indicated file."
  533.     End If
  534.     RBErrFrm.Msg.Text = RB_Msg & Chr$(13) & Chr$(10) & Chr$(13) & Chr$(10) & "Press Help for more information"
  535.     RBErrFrm.SvErr.Caption = RB_err
  536.     RBErrFrm.Show MODAL
  537.     Select Case RB_Erraction
  538.     Case 0
  539.         End
  540.     Case 1
  541.         RB_ErrorHandler = RB_Erraction
  542.     Case 2
  543.         RB_ErrorHandler = RB_Erraction
  544.     End Select
  545.  
  546. End Function
  547.  
  548. Sub RB_LogTask (psTask As String, psForm As String, piFunction As Integer, psComments As String)
  549.     ' Log task performance information
  550.     ' psTask = Name of task being performed
  551.     ' psForm = Name of form task being performed from
  552.     ' piFunction = RB_STARTTASK to indicate the start of a task or
  553.     '              RB_ENDTASK to indicate the end of a task
  554.     ' psComments = any additional information regarding task
  555.  
  556.     Dim iSetEnd As Integer, dduration As Double
  557.     Dim erraction As Integer
  558.  
  559.     On Error GoTo LogTaskErr
  560.  
  561.     If Not RB_LogFileOpen Or Not RB_LogPerformanceData Then
  562.         Exit Sub
  563.     End If
  564.     iSetEnd = False
  565.     If piFunction = RB_ENDTASK Then
  566.         iSetEnd = True
  567.     End If
  568.     If Not RB_TblPerformanceLog.EOF Then
  569.         If IsNull(RB_TblPerformanceLog![End Date/Time]) Then
  570.             iSetEnd = True
  571.         End If
  572.     End If
  573.     If iSetEnd Then
  574.         RB_TblPerformanceLog.Edit
  575.         RB_TblPerformanceLog![End Date/Time] = Now
  576.         dduration = (RB_TblPerformanceLog![End Date/Time] - RB_TblPerformanceLog![Start Date/Time]) / TimeSerial(0, 0, 1)
  577.         RB_TblPerformanceLog!Duration = dduration
  578.         If psComments <> "" Then
  579.             RB_TblPerformanceLog!comments = psComments
  580.         End If
  581.         RB_TblPerformanceLog.Update
  582.     End If
  583.     If piFunction = RB_STARTTASK Then
  584.         RB_TblPerformanceLog.AddNew
  585.         RB_TblPerformanceLog![User Name] = RB_UserName
  586.         On Error Resume Next
  587.         RB_TblPerformanceLog![System/Version] = RB_systemname & "/" & RB_version
  588.         On Error GoTo LogTaskErr
  589.         RB_TblPerformanceLog![Form Name] = psForm
  590.         RB_TblPerformanceLog!Task = psTask
  591.         RB_TblPerformanceLog![Start Date/Time] = Now
  592.         RB_TblPerformanceLog!comments = psComments
  593.         RB_TblPerformanceLog.Update         ' Make sure the row is added
  594.         RB_TblPerformanceLog.Bookmark = RB_TblPerformanceLog.LastModified   ' Get back to row just added
  595.     End If
  596.  
  597.     Exit Sub
  598.  
  599. LogTaskErr:
  600.     erraction = RB_ErrorHandler("RDBLIB.BAS", "RB_LogTask")
  601.     Select Case erraction
  602.     Case 1
  603.         Resume 0      ' Retry option selected
  604.     Case 2
  605.         Resume Next   ' Ignore option selected
  606.     End Select
  607.     
  608.  
  609. End Sub
  610.  
  611. Sub RB_OpenLog ()
  612.     Dim logmdbloc As String      ' Log file location
  613.     Dim IniFileName$, AppName$, KeyName$, DefaultStr$
  614.     Dim nSize%, Numeric%, nDefault, ReturnStr$, sel_button As Integer
  615.     Dim erraction As Integer, temp As String
  616.     
  617.     On Error GoTo OpenLogErr
  618.     
  619.     IniFileName$ = "RDBLOG.INI"        'name of ini file
  620.     AppName$ = "Logging Parameters"     'Name of application or section heading
  621.     KeyName$ = "Database Location"          'Keyword or variable name
  622.     DefaultStr$ = ""            'Default string        (for String variables)
  623.     nSize% = 255                'uncertain - possibly length of fill string
  624.     Numeric% = False               'Tell it we are looking for a string
  625.     ReadIni AppName$, KeyName$, nDefault, DefaultStr$, ReturnStr$, Numeric%, IniFileName$
  626.     logmdbloc = Trim$(ReturnStr$) & "rdblog.mdb"
  627.     If logmdbloc = "" Then
  628.         RB_LogFileOpen = False
  629.         RB_LogPerformanceData = False
  630.         Exit Sub
  631.     End If
  632.  
  633.     On Error Resume Next
  634.     temp = Dir$(logmdbloc)
  635.     If Err = 0 And temp <> "" Then
  636.         On Error GoTo OpenLogErr
  637.         Set RB_DBLog = OpenDatabase(logmdbloc)
  638.         Set RB_TblErrorLog = RB_DBLog.OpenTable("Error Log")
  639.         Set RB_TblPerformanceLog = RB_DBLog.OpenTable("Performance Data")
  640.         RB_LogFileOpen = True
  641.         KeyName$ = "Log Performance Data"          'Keyword or variable name
  642.         DefaultStr$ = ""            'Default string        (for String variables)
  643.         ReadIni AppName$, KeyName$, nDefault, DefaultStr$, ReturnStr$, Numeric%, IniFileName$
  644.         If ReturnStr$ = "True" Then
  645.             RB_LogPerformanceData = True
  646.         Else
  647.             RB_LogPerformanceData = False
  648.         End If
  649.     Else
  650.         RB_LogFileOpen = False
  651.         RB_LogPerformanceData = False
  652.     End If
  653.     KeyName$ = "User Name"          'Keyword or variable name
  654.     DefaultStr$ = ""            'Default string        (for String variables)
  655.     nSize% = 255                'uncertain - possibly length of fill string
  656.     Numeric% = False               'Tell it we are looking for a string
  657.     ReadIni AppName$, KeyName$, nDefault, DefaultStr$, ReturnStr$, Numeric%, IniFileName$
  658.     RB_UserName = ReturnStr$
  659.     On Error GoTo OpenLogErr
  660.  
  661.     Exit Sub
  662.  
  663. OpenLogErr:
  664.     erraction = RB_ErrorHandler("RDBLIB.BAS", "RB_OpenLog")
  665.     Select Case erraction
  666.     Case 1
  667.         Resume 0      ' Retry option selected
  668.     Case 2
  669.         Resume Next   ' Ignore option selected
  670.     End Select
  671.     
  672. End Sub
  673.  
  674.